package com.springboot.erp.controller;


import com.springboot.erp.common.CommonResult;
import com.springboot.erp.entity.Order;
import com.springboot.erp.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 销售订单管理控制器
   * 处理订单的创建、查询、更新和删除操作
   * @author z551199m
   */
@RestController
@RequestMapping("/sales/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建新订单
     */
    @PostMapping
    public CommonResult createOrder(@RequestBody Order order) {
        log.info("创建订单: {}", order);
        return new CommonResult(0, "success", orderService.createOrder(order));
    }

    /**
     * 根据ID获取订单详情
     */
    @GetMapping("/{id}")
    public CommonResult selectOrderById(@PathVariable Long id) {
        log.info("查询订单: ID: {}", id);
        return new CommonResult(0, "success", orderService.selectOrderById(id));
    }

    /**
     * 更新/修改订单信息
       */
    @PutMapping
    public CommonResult updateOrder(@RequestBody Order order) {
        log.info("更新订单: {}", order);
        return new CommonResult(0, "success", orderService.updateOrder(order));
    }

    /**
     * 删除指定订单
       */
    @DeleteMapping("/{id}")
    public CommonResult deleteOrder(@PathVariable Long id) {
        log.info("删除订单，ID: {}", id);
        return new CommonResult(0, "success", orderService.deleteOrder(id));
    }
}